# Set the title bar
if [[ ${TERM} == xterm* ]] || [[ ${TERM} == vte* ]]; then
    echo -ne "\033]0;$(hostname) - $(cat /etc/esos-release)\007"
fi

# A few settings (include the "real" profile)
if [ "$(whoami)" = "root" ]; then
    ulimit -n 10240
fi
ulimit -c unlimited
source /etc/bashrc

# Make the line characters display correctly for certain emulators
export NCURSES_NO_UTF8_ACS=1

if [[ $(tty) =~ /dev/ttyS[0-9] ]]; then
    # Don't run the TUI if we're connected via serial
    echo "Connected via serial ($(tty))..."
    :
elif [ -f "/var/state/esos/no_login_tui" ]; then
    # Don't run the TUI as requested (build option)
    echo "No TUI at login..."
    :
else
    # Run the TUI binary and if it doesn't exit
    # cleanly, fall through to the shell
    /usr/local/bin/esos_tui
    tui_exit=${?}
    if [ ${tui_exit} -eq 0 ]; then
        exit 0
    else
        clear
        echo "Something broke; the TUI exited with ${tui_exit}."
    fi
fi
